<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
	<link href="#springUrl('/static/css/bootstrap.min.css')" rel="stylesheet">
	<link href="#springUrl('/static/css/style.css')" rel="stylesheet">
    <link href="#springUrl('/static/css/jquery-ui.css')" rel="stylesheet">
</head>
<body class="white-bg">
<div class="ibox-content" style="width: 430px;">
   <form id="myForm" class="form-horizontal" autocomplete="off" enctype="multipart/form-data" data-validator-option="{theme:'default'}">
       <div class="form-group"><label class="col-sm-2 control-label">名称</label>
      		<div class="col-sm-10">
			<input type="text" class="form-control" name="itemName" placeholder="请输入商品名称" data-rule="名称:required;itemName">
      		</div>
       </div>
        <!--<div class="form-group"><label class="col-sm-2 control-label">图标</label>
            <div class="col-sm-10">
            <input type="file" class="form-control" name="itemIconAddr" placeholder="请添加商品图片" >
            </div>
        </div>
       <div class="form-group"><label class="col-sm-2 control-label">商品图片</label>
           <div class="col-sm-10">
               <input type="file" class="form-control" name="infoImageAddrs" placeholder="请添加商品图片" >
           </div>
       </div>
       <div class="form-group"><label class="col-sm-2 control-label">商品详情图片</label>
           <div class="col-sm-10">
               <input type="file" class="form-control" name="infoBigImageAddr" placeholder="请添加商品图片" >
           </div>
       </div>-->
       <div class="form-group"><label class="col-sm-2 control-label">成分</label>
           <div class="col-sm-10">
               <input type="text" class="form-control" name="itemCompose"  >
           </div>
       </div>
       <div class="form-group"><label class="col-sm-2 control-label">功效描述</label>
           <div class="col-sm-10">
               <textarea name="itemEffect" class="form-control" data-rule="length[~100]" >$!{item.itemEffect}</textarea>
           </div>
       </div>
       <div class="form-group"><label class="col-sm-2 control-label">制造商</label>
           <div class="col-sm-10">
               <!--使用下拉列表-->
               <input type="text" class="form-control" name="manufactorId" >
           </div>
       </div>
        <div class="form-group"><label class="col-sm-2 control-label">价格</label>
            <div class="col-sm-10">
            <input type="text" class="form-control" name="price"  >
            </div>
        </div>
       <div class="form-group"><label class="col-sm-2 control-label">状态</label>
           <div class="col-sm-10">
               <input name="itemState" value="0" type="hidden" class="form-control" >
               <label class="form-control" >创建</label>
           </div>
       </div>
       <div class="form-group"><label class="col-sm-2 control-label">一级分类</label>
           <div class="col-sm-10">
               <!--从数据库中找出，下拉列表-->
               <select id="itemCategoryPrimary" name="itemCategoryPrimary" class="form-control" >
                   <option selected="selected">请选择</option>
                   <option value="0" >护肤</option>
                   <option value="1" >彩妆</option>
                   <option value="2" >香氛</option>
                   <option value="3" >美发</option>
                   <option value="4" >美体/美甲</option>
                   <option value="5" >个体护理</option>
                   <option value="6" >男士</option>
                   <option value="7" >其他</option>
               </select>
           </div>
       </div>

       <div class="form-group"><label class="col-sm-2 control-label">二级分类</label>
           <div class="col-sm-10">
               <select id="itemCategorySub" class="form-control" name="itemCategorySub" ></select>
           </div>
       </div>
       <div class="form-group"><label class="col-sm-2 control-label">品牌</label>
           <div class="col-sm-10">
               <input type="text" class="form-control" name="brandId"  >
           </div>
       </div>
       <div class="form-group"><label class="col-sm-2 control-label">制造日期</label>
           <div class="col-sm-10">
               <input id="createDate" class="form-control" name="createDate"   >
           </div>
       </div>
       <div class="form-group"><label class="col-sm-2 control-label">排序因子</label>
           <div class="col-sm-10">
               <input type="text" class="form-control" name="sortFactor"   >
           </div>
       </div>
       <div class="form-group"><label class="col-sm-2 control-label">点评佣金比率</label>
           <div class="col-sm-10">
               <input type="text" class="form-control" name="evaluateBonusRate"   >
           </div>
       </div>
       <div class="form-group"><label class="col-sm-2 control-label">点评佣金数量</label>
           <div class="col-sm-10">
               <input type="text" class="form-control" name="evaluateBonusValue"   >
           </div>
       </div>
       <div class="form-group"><label class="col-sm-2 control-label">分享佣金比率</label>
           <div class="col-sm-10">
               <input type="text" class="form-control" name="sharedBonusRate"   >
           </div>
       </div>
       <div class="form-group"><label class="col-sm-2 control-label">分享佣金数量</label>
           <div class="col-sm-10">
               <input type="text" class="form-control" name="sharedBonusValue"   >
           </div>
       </div>
        <div class="form-group">
            <div class="text-center">
                <button class="btn btn-primary" type="submit">提 交</button>
            </div>
        </div>
    </form>
</div>
<script src="#springUrl('/static/js/jquery-2.1.1.js')"></script>
<script src="#springUrl('/static/plugins/nice-validator-0.8.1/jquery.validator.js?local=zh-CN')"></script>
<script src="#springUrl('/static/js/jquery-ui.custom.min.js')"></script>
<script src="#springUrl('/static/js/jquery-ui-1.10.4.min.js')"></script>
<script type="text/javascript">
    $(function(){
        $( "#createDate" ).datepicker({
            altField: "#alternate",
            altFormat: "DD, d MM, yy"
        });
    });
$("#myForm").validator({
    valid: function(form){
        var me = this;
        // 提交表单之前，hold住表单，防止重复提交
        /*me.holdSubmit();*/
        $.ajax({
            type: "POST",
            url: "#springUrl('/item/addItem')",
            data: $(form).serialize(),
            dataType:"text",
            success: function(data){
            	var d = JSON.parse(data);
                if(d.success && d.data){
                	window.parent.location.reload();
                	//当你在iframe页面关闭自身时
                	//var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                	//parent.layer.close(index); //再执行关闭   
                } else {
                	//失败，提交表单成功后，释放hold，如果不释放hold，就变成了只能提交一次的表单
                    /*me.holdSubmit(false);*/
                }
            }
        });
    }
});

    $(function(){
        var secondCats = new Array(8);
        secondCats[0] = new Array("口红","面膜","香水","唇膏","补水","眼霜","卸妆","眉笔","洗面奶");
        secondCats[1] = new Array("口红","面膜","香水","唇膏","补水","眼霜","卸妆","眉笔","洗面奶");
        secondCats[2] = new Array("口红","面膜","香水","唇膏","补水","眼霜","卸妆","眉笔","洗面奶");
        secondCats[3] = new Array("口红","面膜","香水","唇膏","补水","眼霜","卸妆","眉笔","洗面奶");
        secondCats[4] = new Array("口红","面膜","香水","唇膏","补水","眼霜","卸妆","眉笔","洗面奶");
        secondCats[5] = new Array("口红","面膜","香水","唇膏","补水","眼霜","卸妆","眉笔","洗面奶");
        secondCats[6] = new Array("","","","","","","","","","")
        secondCats[7] = new Array("","","","","","","","","","")
        secondCats[8] = new Array("","","","","","","","","","")
        $("#itemCategoryPrimary").change(function(){
           var val = this.value;
            $("#itemCategorySub").get(0).options.length=0;
            $.each(secondCats,function(i,m){
                if(val==i){
                    $.each(secondCats[i],function(j,n){
                        var textNode = document.createTextNode(n);
                        var opEl = document.createElement("option");
                        $(opEl).append(textNode);
                        $(opEl).appendTo($("#itemCategorySub"));
                    });
                }
            });
        });
    });
</script>
</body>
</html>
